import React, {Component} from 'react';
import {observer, inject} from 'mobx-react';
import {withRouter} from 'react-router-dom';
import {ListViewPage} from 'weaver-mobile-page';
import {getRouteParams} from '../../util'
import {ActivityIndicator,Tools} from "weaver-mobile";
const getLabel = Tools.getLabel;

@inject('reportStore')
@withRouter
@observer
export default class Report extends Component {

    componentDidMount() {
        const {reportStore} = this.props;
        const {path} = getRouteParams(this.props);
        reportStore.init(path);
    }

    render() {
        let list, sum;
        const {reportStore, match} = this.props;
        const {isLoading, list1, list2, list3, list4, sum1, sum2, sum3, sum4} = reportStore;
        switch (match.params.path) {
            case 'group':
                sum = sum1;
                list = list1;
                break;
            case 'resource':
                sum = sum2;
                list = list2;
                break;
            case 'dept':
                sum = sum3;
                list = list3;
                break;
            case 'state':
                sum = sum4;
                list = list4;
                break;
            default:
                this.props.history.push('/index/statistics');
                break;
        }
        return (<div className="report-wrapper">
            <div className="report-top-bar-wrapper">
               <div className='report-top-bar'>
               <div className="report-top-title">
                    <span>{getLabel(389842, '数量统计')+":"}{sum}</span>
                </div>
                <i className='report-top-icon icon-cpt icon-zhexiantu'/>
                </div>   
            </div>
            {isLoading ?
                (<div className='loading'><ActivityIndicator animating size='large'/></div>)
                :
                <ListViewPage.Normal
                    showCheck
                    store={list}
                />
            }
        </div>)
    }
}
